export default class ToolsFactory {
    constructor() { }
    getHeigthByLonLat(lon, lat) {
        // 根据经纬度，计算地形高度
        return new Promise((resolve, reject) => {
            var positions = Cesium.Cartographic.fromDegrees(lon, lat);
            var promise = new Cesium.sampleTerrain(viewer.terrainProvider, 13, [
                positions,
            ]);
            promise = Cesium.sampleTerrainMostDetailed(
                viewer.terrainProvider,
                positions
            );
            Cesium.when(
                new Cesium.sampleTerrain(viewer.terrainProvider, 13, [positions]),
                function (updatedPositions) {
                    resolve(updatedPositions[0].height)
                }
            );
        })
    }
    getCoordinatesByLonLat(lon, lat) {
        // 根据经纬度，计算地形高度
        return new Promise((resolve, reject) => {
            var positions = Cesium.Cartographic.fromDegrees(lon, lat);
            var promise = new Cesium.sampleTerrain(viewer.terrainProvider, 13, [
                positions,
            ]);
            promise = Cesium.sampleTerrainMostDetailed(
                viewer.terrainProvider,
                positions
            );
            Cesium.when(
                new Cesium.sampleTerrain(viewer.terrainProvider, 13, [positions]),
                function (updatedPositions) {
                    resolve({
                        lon: lon,
                        lat: lat,
                        height: updatedPositions[0].height
                    })
                }
            );
        })
    }
    calearAllDataSources() {
        // viewer.dataSources.removeAll();
    }
    entityShowHiddenInversion(options) {
        let entBox = null;

        const poOBjArrsource = viewer.dataSources.getByName(options.sourceID) || [];
        if (options.activeSource) {
            poOBjArrsource.forEach(item => {
                item.show = !item.show;
            })
            return
        }


        if (poOBjArrsource.length) {
            entBox = poOBjArrsource[0].entities.getById(options.entityID);
            // 设置线的颜色
            entBox.show = !entBox.show;

        }
    }
}